import request from '@/utils/request'

/**
 * 获取所有角色列表
 * @param {s} page 当前页码
 * @param {*} pagesize 数据条数
 * @returns 
 */
export const reqGetRoleList = (page, pagesize = 10) => {
    return request({
        method: 'get',
        url: '/sys/role',
        params: {
            page,
            pagesize
        }
    })
}

/**
 * 根据id删除角色
 */
export const reqDelRole = (id) => {
    return request({
        method: 'delete',
        url: `/sys/role/${id}`
    })
}

/**
 * 添加角色
 */
export const reqAddRole = (form) => {
    return request({
        method: 'post',
        url: '/sys/role',
        data: form
    })
}

/**
 * 根据ID获取角色详情
 */
export const reqGetRoleDetail = (id) => {
    return request({
        method: 'get',
        url: `/sys/role/${id}`
    })
}

/**
 * 根据ID更新角色
 */
export const reqUpdateRole = (form) => {
    return request({
        method: 'put',
        url: `/sys/role/${form.id}`,
        data: form
    })
}

/**
 * 给角色分配权限
 */
export const reqAssignPermission = (id, permIds) => {
    return request({
        method: 'put',
        url: '/sys/role/assignPrem',
        data: {
            id,
            permIds
        }
    })
}